<?php
/**
 * Pertyler
 * Object Browser Page
 *
 * @author	Emre Hasegeli <hasegeli@gmail.com>
 * @license	GNU General Public License v3
 */

namespace Pertyler;

require_once 'main.php';

if((empty($page->ParentTable)) OR (empty($page->Row)))
	die;

$parentTable = Pertyler_Table::Select($page->ParentTable);

$row = $parentTable->SelectRow($page->Row);

while($parentTable->SelectParentTable())
{
	$requestedTreeNodeIdArray[] = $row->id();

	$row = $row->SelectParentRow();

	$requestedTreeNodeIdArray[] = $row->id() . $parentTable->backgroundName();

	$parentTable = $parentTable->SelectParentTable();
}

$treeView = new \KoolTreeView('treeView');

$treeView->imageFolder = $iconsFolder;

$treeView->styleFolder = 'default/';

$treeView->showLines = true;

$root = $treeView->getRootNode();

$link = new Link('row.php', 'body');

$link->ParentTable = $parentTable->id();

$link->Row = $row->id();

$root->text = $link->Html($row);

$root->image = 'help_page.gif';

$root->showPlusMinus = false;

$treeNodesLink = new Link('ObjectBrowser_rowsObjects.php');

$treeNodesLink->ParentTable = $parentTable->id();

$treeNodesLink->Row = $row->id();

$root->subTreeUrl = $treeNodesLink->Href();

$hTML = '
<div style="padding: 10px;" >
	' . $koolajax->Render() . $treeView->Render() . '
</div>

<script type="text/javascript">';

if(isset($requestedTreeNodeIdArray))
{
	$hTML .= '
	function expand(sender, node)
	{
		if(node.NodeId == \'treeView.root\')';

	foreach(array_reverse($requestedTreeNodeIdArray) AS $requestedTreeNodeId)
		$hTML .= '
			treeView.getNode(\'' . $requestedTreeNodeId . '\').expand();
		else if(node.NodeId == \'' . $requestedTreeNodeId . '\')';

	$hTML .= '
			treeView.registerEvent(\'OnExpand\', function() {});
	}

	treeView.registerEvent(\'OnExpand\', expand);';
}

$hTML .= '
	treeView.getNode(\'treeView.root\').expand();
</script>';

echo $page->HTML($hTML);




